/*
 * GLCanvasPane.h
 */

#ifndef GLCANVASPANE_H_
#define GLCANVASPANE_H_

#define MAXVERTS 10000
#define NCOLORS 1000
#define MAX(a,b) (((a)>(b))?(a):(b))

#include <wx/wx.h>
#include <wx/glcanvas.h>
#include "GeoData.h"

static int gl_attrib_system[20] = { WX_GL_RGBA, WX_GL_MIN_RED, 1, WX_GL_MIN_GREEN, 1,
          WX_GL_MIN_BLUE, 1, WX_GL_DEPTH_SIZE, 1, None, None };

class GLCanvasPane : public wxGLCanvas{

        ///Structure with red, green, and blue components of color in decimal form
        struct ColorTable {
                float Red;
                float Green;
                float Blue;
        };

        ColorTable Rainbow[NCOLORS];
        int display_type;
        GeoData *data;
        int width, length;
        double max, min;

        GLfloat xrot;
        GLfloat yrot;

        GLboolean smooth;
        GLboolean lighting;

public:

        GLCanvasPane(wxWindow* parent,
                        wxWindowID winid = wxID_ANY,
                        const wxPoint& pos = wxDefaultPosition,
                        const wxSize& size = wxDefaultSize,
                        long style = wxTAB_TRAVERSAL | wxNO_BORDER,
                        const wxString& name = _T("GLCanvasPane"),
                        int *gl_attrib = gl_attrib_system
                );

        virtual ~GLCanvasPane();

        void Draw1();
        void DrawSurface();
        void HeightMap();
        void Init();
    void SetDataPointer(GeoData *ptr, int x, int y);
    int GetColorIndex(int x, int z) { return ((data->GetValue(x,z)-min)*NCOLORS/(max-min)); }
    float GetHeight(int x, int z) { return 10*((data->GetValue(x,z)-min)/(max - min) - 0.5f); }
    void SetDisplayType(int type) { display_type = type; Draw1(); SwapBuffers(); }
    void Scale();

        void OnPaint(wxPaintEvent& event);
        void OnSize(wxSizeEvent& event);
        void OnEraseBackground(wxEraseEvent& event);
        void OnChar(wxKeyEvent& event);
        void OnMouseEvent(wxMouseEvent& event);

        DECLARE_EVENT_TABLE();

};

#endif /* GLCANVASPANE_H_ */
